<template>
  <div class="seed_login">
    <!--<img class="a123" src="../../assets/images/loginbg.png" alt="">-->
    <div class="seed_login_box">
      <div class="seed_login_head">种子应用后台</div>
      <div class="seed_reg_stction">
        <p class="seed_stction_p1">忘记密码</p>
      </div>
      <div class="seed_login_form">
        <input class="seed_login_name" type="text" name="name" placeholder="手机号/用户名"  v-model="register_info.account">
        <input class="seed_login_password" type="password" name="password" placeholder="密码" v-model="register_info.password">
        <input class="seed_login_password" type="password" name="apassword" placeholder="确认密码" v-model="register_info.repassword">
        <div class="seed_reg_yzm">
          <input class="seed_reg_yzm_t" type="text"  name="yzm" placeholder="验证码" v-model="register_info.vcode">
          <input class="seed_reg_yzm_b" type="button" name="yzm" value="获取验证码" @click="get_sms"  v-show="show">
          <input class="seed_reg_yzm_b" type="button" name="yzm" value="验证码" v-model="count_desc" v-show="!show">
        </div>
        <div class="seed_reg_xx"></div>
        <input class="seed_login_bt" type="button" value="找回密码">
      </div>
      <div class="seed_register">
        <span >已有账号</span>
        <router-link :to="{name:'passport-login'}"><a>立即登录</a>
        </router-link>
      </div>
    </div>
  </div>
</template>
<script>
import * as validator from '@/validator'
export default {
  data () {
    return {
      register_info: {
        account: '',
        password: '',
        repassword: '',
        vcode: ''
      },
      show: true,
      count: '',
      timer: null,
      count_desc: ''
    }
  },
  methods: {
    get_sms () {
      const TIME_COUNT = 60
      this.count_desc = TIME_COUNT + 's后重新发送'
      if (!validator.phone(this.register_info.account)) {
        this.$toast('请输入有效手机号')
        return false
      }
      if (!this.timer) {
        this.count = TIME_COUNT
        this.show = false
        this.timer = setInterval(() => {
          if (this.count > 0 && this.count <= TIME_COUNT) {
            this.count--
            this.count_desc = this.count + 's后重新发送'
          } else {
            this.show = true
            clearInterval(this.timer)
            this.timer = null
          }
        }, 1000)
      }
    },
    register () {
      if (!validator.phone(this.register_info.account)) {
        this.$toast('请输入有效手机号')
        return false
      }
      if (this.register_info.password === '') {
        this.$toast('密码不能为空')
        return false
      }
      if (this.register_info.password !== this.register_info.repassword) {
        this.$toast('两次密码输入不同，请重新输入')
        return false
      }
      if (this.register_info.vcode === '') {
        this.$toast('验证码不能为空')
        return false
      }
      this.$request.forget(this.register_info).then(data => {
        this.$toast('提交成功')
        this.$utils.setCookie('token', data, 365)
        setTimeout(() => {
          this.$router.push({name: 'Home'})
        }, 500)
      })
    }
  }
}
</script>
